﻿<!DOCTYPE html>
<html lang="en">
<head>
<title>山东大学(威海)贴吧官方登陆</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<!--图标样式-->
<link rel="stylesheet" type="text/css" href="fonts/font-awesome-4.7.0/css/font-awesome.min.css">

<!--布局框架-->
<link rel="stylesheet" type="text/css" href="css/util.css">

<!--主要样式-->
<link rel="stylesheet" type="text/css" href="css/main.css">

</head>

<body>
    <div class="alert"></div>
    <div class="limiter">
        <div class="container-login100" style="background-image: url('images/logo.jpg');">
            <div class="wrap-login100 p-t-190 p-b-30">
                <div class="login100-form validate-form">
                    <div class="login100-form-avatar">
                        <img src="images/logo.jpg" alt="AVATAR">
                    </div>

                    <span class="login100-form-title p-t-20 p-b-45">Welcome</span>

                    <div class="wrap-input100 validate-input m-b-10" data-validate="请输入用户名">
                        <input class="input100" type="text" name="username" placeholder="用户名" autocomplete="off">
                        <span class="focus-input100"></span>
                        <span class="symbol-input100">
                            <i class="fa fa-user"></i>
                        </span>
                    </div>

                    <div class="wrap-input100 validate-input m-b-10" data-validate="请输入密码">
                        <input class="input100" type="password" name="pass" placeholder="密码">
                        <span class="focus-input100"></span>
                        <span class="symbol-input100">
                            <i class="fa fa-lock"></i>
                        </span>
                    </div>

                    <div class="container-login100-form-btn p-t-10">
                        <button class="login100-form-btn" onclick="submitLogin()">登 录</button>
                    </div>

                   <!--  <div class="text-center w-full p-t-25">
                        <a href="#" class="txt1">忘记密码？</a>
                    </div> -->

                    <div class="text-center w-full p-t-25">
                        <a class="txt1" href="registry.html">
                            立即注册
                            <i class="fa fa-long-arrow-right"></i>
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="js/jquery-1.12.4.min.js"></script>
    <script src="js/jquery.cookie.js"></script>
    <script src="js/main.js"></script>
    <script type="text/javascript">

        (function ($) {
            $.getUrlParam = function (name) {
                var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
                var r = window.location.search.substr(1).match(reg);
                if (r != null) return unescape(r[2]); return null;
            }
        })(jQuery);

        $(function(){
            var token = $.cookie("token");
            var redirect = $.getUrlParam("redirect")
            if(token) {
                $.ajax({
                    url: 'https://www.maksdu.com/app/sauth',
                    method: 'get',
                    headers: {
                        'request_access_token':token
                    },
                    success: function(result) {
                        if(result.code == 200) {
                            $.cookie("username", result.value.name, { expires: 1, domain: '.maksdu.com' });
                            window.localStorage.setItem('owninfo', JSON.stringify(result.value));
                            $('.alert').html('自动登录').addClass('alert-success').show().delay(1500).fadeOut();
                            if(redirect) {
                                window.location.replace(redirect);
                            } else {
                                window.location.replace("https://www.maksdu.com/home/index.html");
                            }
                        } else {
                            $("input[name='username']").val($.cookie("username"));
                        }
                    }
                })
            } else
                $("input[name='username']").val($.cookie("username"));
        })

        function submitLogin() {
            
            var unm = $("input[name='username']").val();
            var pwd = $("input[name='pass']").val();
            var redirect = $.getUrlParam("redirect");
            $.ajax({
                url:'https://www.maksdu.com/app/pwd/login',
                method: 'post',
                data: {
                    username:unm,
                    password:pwd
                },
                success: function(result) {
                    if(result.code == 200) {
                        var success = result.result;
			            if(success.auth_is_ok && success.value.userId) {
                            $('.alert').html('登录成功').addClass('alert-success').show().delay(1500).fadeOut();
                            setTimeout(function(){
                                var token = success.value.token;
                                $.cookie("username", unm, { expires: 1, domain: '.maksdu.com' });
                                $.cookie("token", token, {expires: 1,domain:'.maksdu.com'});
                                window.localStorage.setItem('token',token);
                                window.localStorage.setItem('loginStatus', true);
                                window.localStorage.setItem('owninfo', JSON.stringify(success.value.extendsAttributes.user));
                                window.localStorage.setItem('friendsId', success.value.extendsAttributes.friendsId);
                                window.localStorage.setItem('userId', success.value.extendsAttributes.user.id);
                                if(redirect) {
                                    window.location.replace(redirect);
                                } else
                                    window.location.replace("https://www.maksdu.com/home/index.html");
                            },1000);
                        } else {
                            $('.alert').html('用户名密码验证错误').addClass('alert-danger').show().delay(1500).fadeOut();
                            reload();
                        }
                    } else {
                        $('.alert').html('登录失败').addClass('alert-danger').show().delay(1500).fadeOut();
                        reload();
                    }
                }
            })
        }

    </script>

</body>
</html>
